package com.demo.salary.payrolldatabase;

import com.demo.salary.payrolldomain.Employee;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class PayrollDatabase {

    private final static Map<Integer, Employee> itsEmployees = new HashMap<>();
    private final static Map<Integer, Integer> memberEmployee = new HashMap<>();

    public static Employee getEmployee(int empId) {
        return itsEmployees.get(empId);
    }

    public static Employee delEmployee(int empId) {
        return itsEmployees.remove(empId);
    }

    public static void addEmployee(int empId, Employee employee) {
        itsEmployees.put(empId, employee);
    }

    public static void clear() {
        itsEmployees.clear();
    }

    public static void addUnionMember(int memberId, Employee employee) {
        memberEmployee.put(memberId, employee.getEmpId());
    }

    public static Employee getEmployeeByUnionMember(int memberId) {
        return itsEmployees.get(memberEmployee.get(memberId));
    }

    public static void removeUnionMember(int memberId) {
        itsEmployees.remove(memberId);
    }

    public static List<Integer> getAllEmployeeIds() {
        List<Integer> ids = new ArrayList<>();
        itsEmployees.forEach((k, v) -> {
            ids.add(k);
        });
        return ids;
    }
}
